<?php 
namespace Admin\Controller;
 use Think\Controller;
class UserController extends CommenController {
    public function index(){
    	

    	$user = M('user');
    	$count = $user->count();
    	$page = new \Think\Page($count,8);
    	$show = $page->show();
    	$userlist = $user->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
    	$this->assign("page",$show);
    	$this->assign('userlist',$userlist);

    	$this->display();
    }

    public function delete(){
        $id = $_GET['id'];
        $m = M('user');
        $result = $m->delete($id);
        if($result > 0){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    public function xianshi(){
        $id = $_GET['id'];
        $m = M('user');
        $ass=$m->where("id = $id")->save(array('status' => '0'));
        if($ass > 0){
            $this->success('修改成功');
        } else{
            $this -> error('修改失败');
        }

    }

    public function jinyong(){
        $id = $_GET['id'];dump($id);
        $m = M('user');
        $data = $m -> where("id = $id") ->save(array('status' => '1'));
        if($data > 0){
            $this->success('修改成功');
        } else{
            $this -> error('修改失败');
        }
    }

    public function power(){
        $pow = $_POST['pow'];
        $id = $_POST['userid'];
        dump($pow);
        if($pow == ""){
            $this->error('修改失败');
        }
        $m = M('user');
        $data = $m ->where("id = $id")->save(array('power'=>$pow));
        $pc = $m ->where("power = 2")->count();
        if($pc >1){
            $this ->error('只能有一名超级管理员');
        }
        if($data > 0){
            $this->success('修改成功');
        }else{
            $this -> error('修改失败');
        }

    }
}